package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.annotation.RequireLogin;
import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.query.TravelQuery;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private ITravelService travelService;

    @RequestMapping("/search")
    @ResponseBody
    public Object search(String regionId){

        List<Destination> list = destinationService.queryHotDestination(regionId);

        return JsonResult.success(list);
    }

    @RequestMapping("/hotRegion")
    @ResponseBody
    public Object hotRegion(){

        return JsonResult.success(regionService.queryHotRegion());
    }

    @GetMapping("/toasts")
    public Object toasts(String destId){

        return JsonResult.success(destinationService.queryToasts(destId));
    }

    @GetMapping("/detail")
    public Object detail(String destId){

        return JsonResult.success(destinationService.get(destId));
    }

    @GetMapping("/catalogs")
    public Object catalogs(String destId){

        List<StrategyCatalog> list = strategyCatalogService.findByDestId(destId);

        return JsonResult.success(list);
    }

    @GetMapping("/strategies/viewnumTop3")
    public Object viewnumTop3(String destId){

        List<Strategy> list = strategyService.queryViewNumTop3(destId);

        return JsonResult.success(list);
    }

    @GetMapping("/query")
    public Object query(TravelQuery qo){

        Page<Travel> page = travelService.query(qo);

        return JsonResult.success(page);
    }

    @GetMapping("/travels/viewnumTop3")
    public Object travelsViewnumTop3(String destId){

       List<Travel> list =  travelService.queryTravelsViewnumTop3(destId);

       return JsonResult.success(list);
    }

    @GetMapping("/editpermission")
    public Object editPermission(String id){

        UserInfo userInfo = travelService.editPermission(id);

        return JsonResult.success(userInfo);
    }
}
